<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                                 |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
//  $Id: faq_categories.php 895 2005-01-07 18:39:16Z ajeh $
//

  require('includes/application_top.php');
  //require(DIR_WS_MODULES . 'faq_cat_header_code.php');
  $action = (isset($_GET['action']) ? $_GET['action'] : '');
  
  if($action=='del' && isset($_GET['k_id']) && (int)$_GET['k_id'] > 0 && isset($_GET['categories_id']) && (int)$_GET['categories_id'] > 0){
  	  $order_reviews_description = $db->Execute("DELETE FROM `".TABLE_CATEGRIES_KEYWROD."` WHERE `k_id` = ".(int)$_GET['k_id']);
	  echo zen_redirect(zen_href_link('categories_keyword.php?categories_id='.(int)$_GET['categories_id'].'&action=add_keyword'));
  }
  
  if($action=='edit' && isset($_GET['k_id']) && (int)$_GET['k_id'] > 0 && isset($_GET['categories_id']) && (int)$_GET['categories_id'] > 0){
  	  $query = "SELECT `k_id`,`keyword`,`categories_id` FROM `".TABLE_CATEGRIES_KEYWROD."` WHERE `k_id` = ".(int)$_GET['k_id'];	
	  $data = $db->Execute($query);
  }

  if(isset($_POST['update_kid']) && $_POST['update_kid'] == 1){
      $categories_id = zen_db_prepare_input($_POST['categories_id']);
	  $keyword = zen_db_prepare_input($_POST['keyword']);
	  $k_id = zen_db_prepare_input($_POST['k_id']);
	  $db->Execute("UPDATE `".TABLE_CATEGRIES_KEYWROD."` SET `keyword` = '".$keyword."' WHERE `k_id` = ".$k_id);
	  echo zen_redirect(zen_href_link('categories_keyword.php?categories_id='.$categories_id.'&action=add_keyword'));
  }
  
  if(isset($_POST['categories_id']) && isset($_POST['inset']) && (int)$_POST['categories_id'] > 0 && $_POST['inset']==1){
  	  $keyword = zen_db_prepare_input($_POST['keyword']);
	  $categories_id = zen_db_prepare_input($_POST['categories_id']);
	  $db->Execute("INSERT INTO `".TABLE_CATEGRIES_KEYWROD."` (`keyword` ,`categories_id`)VALUES ('".$keyword."', '".$categories_id."');");
  }
  
  if(empty($action)){
  	  $query = "SELECT c.categories_id,parent_id,cd.categories_name,cd.categories_id 
	                       FROM `".TABLE_CATEGORIES."` c, `".TABLE_CATEGORIES_DESCRIPTION."` cd 
						   WHERE c.categories_id = cd.categories_id and `parent_id`=0 and language_id = '" . $_SESSION['languages_id'] . "'";
  }
  
  if($action=='add_keyword'){
  	  $query = "SELECT `k_id`,`keyword`,`categories_id` FROM `".TABLE_CATEGRIES_KEYWROD."` WHERE `categories_id`=".(int)$_GET['categories_id']." ORDER BY `k_id` ASC";
  }
    
  $colspan = (empty($action))?3:6;
  
  $link_id = (empty($action))?'categories_id':'k_id';
  
  $images = (empty($action))?'folder.gif':'preview.gif';
  
  
// check if the catalog image directory exists
  if (is_dir(DIR_FS_CATALOG_IMAGES)) {
    if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
  } else {
    $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript">
  <!--
  function init()
  {
    cssjsmenu('navbar');
    if (document.getElementById)
    {
      var kill = document.getElementById('hoverJS');
      kill.disabled = true;
    }
  if (typeof _editor_url == "string") HTMLArea.replaceAll();
  }
  // -->
</script>
<script language="javascript">
function fsubmit(obj){
obj.submit();
}
</script>
<?php if ($action != 'new_product_meta_tags' && $editor_handler != '') include ($editor_handler); ?>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="init()">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="0">
  <tr>
<!-- body_text //-->
    <td width="100%" valign="top">
          </tr>
		  
		  	<tr>
			  <td height="30" colspan="<?php echo $colspan;?>" class="pageHeading"><?php echo TEXT_COTEGORIES_KEYWORD_MANAGEMENT;?></td>
			  </tr>
          <tr>
		  <td class="smallText" align="center">
		  
		  <?php if($action=='inset'){ ?>
		  <form action="categories_keyword.php?categories_id=<?php echo (int)$_GET['categories_id'];?>&action=add_keyword" name="add_key" id="add_key" method="post">
			<table width="100%" cellspacing="0" cellpadding="2" border="0">
				  <tr>
					<td width="70">Keyword:</td>
					<td><input type="text" name="keyword" value="" size="40"></td>
				  </tr>
				  <tr>
					<td width="70">&nbsp;&nbsp;</td>
					<td>
					<input type="hidden" value="1" name="inset">
					<input type="hidden" value="<?php echo (int)$_GET['categories_id'];?>" name="categories_id">
					<input type="image" onClick="javascript:history.go(-1)" value="" name="button" src="includes/languages/english/images/buttons/button_back.gif"/>&nbsp;&nbsp;
					<input type="image" onClick="javascript:fsubmit(document.add_key)" value="" src="includes/languages/english/images/buttons/button_insert.gif">
					</td>
				  </tr>
			 </table>
			</form>
		  <?php }elseif($action=='edit'){?>
		  <form action="categories_keyword.php?k_id=<?php echo $data->fields['k_id'];?>&action=edit&categories_id=<?php echo $data->fields['categories_id'];?>" name="add_key" id="add_key" method="post">
			<table width="100%" cellspacing="0" cellpadding="2" border="0">
				  <tr>
					<td width="70">Keyword:</td>
					<td><input type="text" name="keyword" value="<?php echo $data->fields['keyword'];?>" size="40"></td>
				  </tr>
				  <tr>
					<td width="70">&nbsp;&nbsp;</td>
					<td>
					<input type="hidden" value="1" name="update_kid">
					<input type="hidden" value="<?php echo $data->fields['categories_id'];?>" name="categories_id">
					<input type="hidden" value="<?php echo $data->fields['k_id'];?>" name="k_id">
					<input type="image" onClick="javascript:history.go(-1)" value="" name="button" src="includes/languages/english/images/buttons/button_back.gif"/>&nbsp;&nbsp;
					<input type="image" onClick="javascript:fsubmit(document.add_key)" value="" src="includes/languages/english/images/buttons/button_update.gif">
					</td>
				  </tr>
			 </table>
			</form>
		  <?php }else{ ?>
		  <table width="100%" cellspacing="0" cellpadding="2" border="0">
              <tbody>
			  <tr class="dataTableHeadingRow">
                <td width="20" align="right" class="dataTableHeadingContent">ID</td>
                <td class="dataTableHeadingContent">Categories</td>
				<?php if(!empty($action)){?>
                <td align="left" class="dataTableHeadingContent"></td>
                <td width="50" align="center" class="dataTableHeadingContent">Keyword</td>
                <td align="right" class="dataTableHeadingContent">Action&nbsp;</td>
				<?php }?>
              </tr>
			  <!--循环开始-->
			  
			  <?php 
			    $chapter_query_numrows = 20;
			    $tickets_split = new splitPageResults($_GET['page'],MAX_DISPLAY_SEARCH_RESULTS_CUSTOMER, $query, $chapter_query_numrows);
				$sql_query = $db->Execute($query);
			  	while(!$sql_query->EOF){
				$url = (empty($action))?"categories_keyword.php?categories_id=".$sql_query->fields[$link_id]."&action=add_keyword":"categories_keyword.php?k_id=".$sql_query->fields[$link_id]."&action=edit&&categories_id=".$sql_query->fields['categories_id']."";
			  ?>
			  <tr onClick="document.location.href='<?php echo zen_href_link($url)?>'" onMouseOut="rowOutEffect(this)" onMouseOver="rowOverEffect(this)" class="dataTableRow">
                <td width="20" align="right" class="dataTableContent"><?php echo $sql_query->fields[$link_id];?></td>
                <td class="dataTableContent"><a href="http://localhost:8016/demo/admin/faq_categories.php?fcPath=1&amp;pID=3&amp;action=new_faq_preview&amp;read=only&amp;page=1"><img height="16" width="16" border="0" title=" Preview " alt="Preview" src="images/icons/<?php echo $images;?>"></a>&nbsp;<?php echo $sql_query->fields['categories_name'];?></td>
			   <?php if(!empty($action)){?>
                <td class="dataTableContent"></td>
                <td align="right" class="dataTableContent"><?php echo $sql_query->fields['keyword'];?></td>
                <td align="right" class="dataTableContent">
        <a href="<?php echo zen_href_link("categories_keyword.php?".$link_id."=".$sql_query->fields[$link_id]."&action=edit&categories_id=".(int)$_GET['categories_id']."")?>"><img height="17" width="17" border="0" title=" Edit " alt="Edit" src="images/icon_edit.gif"></a>        <a href="<?php echo zen_href_link("categories_keyword.php?k_id=".$sql_query->fields['k_id']."&action=del&categories_id=".(int)$_GET['categories_id']."")?>"><img height="17" width="17" border="0" title=" Delete " alt="Delete" src="images/icon_delete.gif"></a></td>
              </tr>
			  <?php
			    } 
			    $sql_query->MoveNext();
			    }
			  ?>
			   <!--循环结束-->
          <tr>
			<?php
			// Split Page
			if ($chapter_query_numrows > 0) {
			  if (empty($pInfo->chapter_id)) {
				$pInfo->chapter_id= $pID;
			  }
			?>
			   <td class="smallText" align="center" colspan="6"><?php echo $tickets_split->display_count($chapter_query_numrows, MAX_DISPLAY_RESULTS_CATEGORIES, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS) . '<br>' . $tickets_split->display_links($chapter_query_numrows, MAX_DISPLAY_RESULTS_CATEGORIES, MAX_DISPLAY_PAGE_LINKS, $_GET['page'], zen_get_all_get_params(array('page', 'info', 'x', 'y', 'pID')) ); ?></td>
			<?php
			}
			// Split Page
			?>
          </tr>
		  <?php if(!empty($action)){?>
		  <tr>
		  <td class="smallText" align="center" colspan="6" style="padding-top:5px;"><input type="image" onClick="javascript:history.go(-1)" value="" name="button" src="includes/languages/english/images/buttons/button_back.gif"/>&nbsp;&nbsp;<a href="categories_keyword.php?categories_id=<?php echo (int)$_GET['categories_id']?>&action=inset"><?php echo zen_image_submit('button_new_keyword.gif');?></a>
		  </td>
		  </tr>
		  <?php }?>
                </tbody>
				</table>
		 <?php }?>
				
				</td>
              </tr>
            </tbody>
		</table>	
  </td>
          </tr>
        </table></td>
      </tr>
    </table>
    </td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br />
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
